package com.xu.blog_after_end.dao;

import com.xu.blog_after_end.po.Type;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;

public interface TypeRepository extends JpaRepository<Type, Long> {
    Type findByName(String name);   // 根据名称查询分类

    // 修改查询，按博客数量降序排序
    @Query("SELECT t FROM Type t LEFT JOIN t.blogs b GROUP BY t ORDER BY COUNT(b) DESC")
    List<Type> findTop(Pageable pageable);
}

